<?php
	require_once($_SERVER['DOCUMENT_ROOT']."/classes/database.class.php");
	require_once($_SERVER['DOCUMENT_ROOT']."/classes/ColorPair.class.php");
	require_once($_SERVER['DOCUMENT_ROOT']."/includes/define.php");
		
	class MatrixColorsShapes{
		var $matrix;
		var $lastPair;
		var $stepsNumber;
		var $actualStep;
		var $shape;
		
		public function MatrixColorsShapes($shapeName){
			$this->matrix = array();
			$this->lastPair = "";
			$this->actualStep = 1;
			$this->createMatrix($shapeName);
		}
		
		public function createMatrix($shapeName){
			$this->shape = new Shape($shapeName);
			$bd = new Database(MYSQL_DB_HOST,MYSQL_DB_LOGIN,MYSQL_DB_PASSWORD,MYSQL_DB_NAME);
			$bd->connect();
			$allColorsData = $bd->query('SELECT * FROM colors WHERE isActivated = \'1\';');
			while($colorData = mysql_fetch_assoc($allColorsData)){
				$allColors[] = new Color($colorData);
			}
			while(!empty($allColors)){
				foreach($allColors as $secondColor){
					if($allColors[0] != $secondColor) $this->matrix[] = new ColorPair($allColors[0],$secondColor,$this->shape);
				}
				array_shift($allColors);
			}		
			$this->stepsNumber = count($this->matrix);
		}
		
		public function getNextColorPair(){
			$randKey = array_rand($this->matrix);
			$colorPair = $this->matrix[$randKey];
			unset($this->matrix[$randKey]);
			return $colorPair;
		}
	}
?>